package com.dmpp.mes.service.impl;

import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.UserMapper;
import com.dmpp.mes.parameterInfo.User;
import com.dmpp.mes.service.UserServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service(value = "UserServer")
public class UserServerImpl implements UserServer {


    @Autowired
    private UserMapper mapper;


    @Override
    public ResponseData login(User user) {
        ResponseData responseData = new ResponseData();
        User user1 = mapper.login(user);
        if (user1 != null){
           /* if (user1.getUserName().equals(user.getUserName()) ){
                if (user1.getUserPassword().equals(user.getUserPassword())){*/
                 //   System.out.println(UUID.randomUUID().toString());
                    user.setRandomNo(UUID.randomUUID().toString());
                    user.setId(user1.getId());
                    mapper.updateByRandomNo(user);
                    responseData.setData(user);
              /*  }else {
                    responseData.setCodeEnum(RespEnum.ERROR1002);
                }
            }else {
                responseData.setCodeEnum(RespEnum.ERROR1001);
            }*/
        }else {
            responseData.setCodeEnum(RespEnum.ERROR1001);
        }
        return responseData;
    }

    @Override
    public ResponseData updateByRandomNo(User user) {
        ResponseData responseData = new ResponseData();
        mapper.updateByRandomNo(user);
        return responseData;
    }

    @Override
    public ResponseData findAll(User user) {
        ResponseData responseData = new ResponseData();
        responseData.setData( mapper.findAll(user));
        return responseData;
    }

    @Override
    public String getRole(User user) {

        return mapper.getRole(user);
    }
}
